package com.opages.cloud.common.config;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

/**
 * 
 * 复制RequestMappingHandlerMapping代码</br>
 * 问题描述：Controller上同时出现@FeignClient与@RequestMapping注解时会被重复注册Bean</br>
 * 解决方案：修改isHandler方法，增加判断</br>
 */
public class OpagesRequestMappingHandlerMapping extends RequestMappingHandlerMapping {

    @Override
    protected boolean isHandler(Class<?> beanType) {
        // 判断不是Feign注解的API类，且Controller必须注解了Controller或继承了BaseController父类
        return super.isHandler(beanType) && (!AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class)
                || AnnotatedElementUtils.hasAnnotation(beanType, Controller.class));
    }



}
